<?php if (!defined('BASEPATH')) exit ('No direct script access allowed');

class Pages extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->load->helper('url');
		$this->load->library('encrypt');
		$this->load->helper(array('form', 'url'));
  		$this->load->library('form_validation');
  		$this->load->model('user_model');
		$this->load->model('lookup_model');
		$this->load->model('level_model');
	}

	public function view() {
		$page = rawurldecode($this->uri->segment(2));
		$page = $page != ''?$page:'home';
		
		if($page == 'logout'){
			$this->session->unset_userdata('user');
			$this->session->unset_userdata('adminflag');
			$page = 'home';
		}
		if ( ! file_exists('application/views/pages/'.$page.'.php'))
	  	{
	    	// 页面不存在
	    	show_404();
	  	}
	  
	  	$data['title'] = ucfirst($page); // 将title中的第一个字符大写
	  
	  	if($page == 'home'){
	  		$data = $this->home($data);
	  	}
	  	$this->load->view('templates/header', $data);
	  	$this->load->view('pages/'.$page, $data);
	  	$this->load->view('templates/footer', $data);
	}
	
	private function home($data){
		$levels = $this->level_model->list_level(array());
		$data['levels'] = $levels;
		return $data;
	}
	
}
